################
#PSRM: Explaining Support for Redistribution: Social Insurance Systems and Fairness
#
#Observational Analysis ESS
#Figure B 6
#
#Verena Fetscher
#July 2022
####################

####################
# Load data
####################
source("dataframes.R")


##########################
#Benefit concentration indicators versus alternative measures: Benefit concentration and welfare spending
##########################

cor.test(data_sub$social_spending,data_sub$benefitsAvgYear, method=c("pearson"))

##########################
#Figure B.6: Benefit concentration and social spending (% of GDP), averaged over 2002- 2014.
##########################

data_sub%>%
  group_by(country)%>%
  summarize(benefits=mean(benefitsAvg),
            social_spending=mean(social_spending))%>%
  ggplot(aes(x=benefits, y=social_spending)) + 
  geom_point() + 
  #ggtitle("Benefit concentration and social expenditure (total, % of GDP)") + 
  geom_smooth(method=lm, se=T) + 
  scale_x_continuous(name = "Benefit concentration", limits = c(0, 1)) + 
  scale_y_continuous(name = "Social spending (% of GDP)") + 
  theme_bw()


##########################
#Save figure
##########################

ggsave(file="figure_b6.pdf", height = 5.83, width = 8.27, units = "in")
